<?php
/*he 区外学生成绩导入操作*/
class OutController extends FController {

    public $user_school_list;
    public $user_subject_list;
    public $user_role_list;
    public $exam_id;
	public function init() {
		parent::init();
		if (empty($this->cLoginUser)) {
			$this->redirect($this->createUrl('/site/login'));
        } else {
            $userLoginUser = $this->cLoginUser;
            $this->user_role_list = isset($userLoginUser['cuser']['role_id']) ? $userLoginUser['cuser']['role_id'] : '';
            $this->user_school_list = isset($userLoginUser['cuser']['school']['school_id']) ? $userLoginUser['cuser']['school']['school_id'] : '';
            $this->user_subject_list = isset($userLoginUser['cuser']['school']['subject_id']) ? $userLoginUser['cuser']['school']['subject_id'] : '';
            $zRow = new ZRole();
            //得到学校对应的考试
            $exam_list = $zRow->_getSchoolExam($this->user_school_list);
            if (!empty($exam_list)) {
                $this->exam_id = implode(',', $exam_list);
            }
		}
		$this->commonScript();
		Yii::app()->clientScript->registerCssFile(THEME_CSS_URL . '/base.css');
		Yii::app()->clientScript->registerCssFile(THEME_CSS_URL . '/master.css');
		Yii::app()->clientScript->registerCssFile(THEME_CSS_URL . '/module_Sip.css');
	}
	//导入
	public function actionIndex() {
        Yii::app()->clientScript->registerScriptFile(STATICS_URL . "/js/ajaxfileupload.js");
		$this->title='区外考试成绩导入';
        $where = $qWhere =  '';
                //权限判断
                if ($this->user_role_list != 1 && !empty($this->exam_id)) {
                    $where = ' AND "exam_id" IN (' . $this->exam_id . ')';
            $zExam = new zExam();
            $qWhere = $zExam->_getSchoolInfoList($this->user_school_list);
        }
        $date['ztask'] = ZTask::_getExamAll($where);
		$date['nojoin'] = Nojoin::_getNojoinAll();
		$limit = 8;
		$date['exam_id'] = $this->request->getParam('exam_id',0);
        $data_exam = $data = $pages = array();
        if ($date['exam_id'] > 0) {
        $sql = 'SELECT *  FROM "{{import_error}}" WHERE "type"=4 AND "exam_id"='.$date['exam_id'];
		$count = 'SELECT count("id") FROM "{{import_error}}" WHERE  "type"=4 AND "exam_id" ='.$date['exam_id'];
		$data = ZCommon::getDaoPageList($sql, $count, $limit);
            if (!empty($data)) {
                $pages = isset($data['pages']) ? $data['pages'] : '';
            } else {
                $data_exam = self::_GetExamList($date['exam_id'],$qWhere);
                $pages = isset($data_exam['pages']) ? $data_exam['pages'] : '';
            }
        } else {
            $data_exam = self::_GetExamList($date['exam_id'],$qWhere);
            $pages = isset($data_exam['pages']) ? $data_exam['pages'] : '';
        }
		$pageUrl = $this->createUrl('/scores/out/index',array('exam_id'=>$date['exam_id']));
		$this->render('import', array(
            'data' => isset($data['listDatas']) ? $data['listDatas'] : '',
            'pages' => $pages,
            'data_exam' => isset($data_exam['listDatas']) ? $data_exam['listDatas'] : '',
		'pageUrl' => $pageUrl,
		'date' => $date
		));
	}
	//上传文件
	public function actionImport(){
		if(!empty($_POST['submit'])){
			$data = $this->request->getParam('info');
			if (empty($data['exam_id']) || empty($_FILES['file']['name'])) {
				$this->redirect('/scores/out/index/error/1');exit;
			}
			if (isset($_FILES['file'])) {
				$file_name_list = ZFileUpload::getUniqueID();  //得到唯一名称
				$file_name = $_FILES['file']['name'];
				$extend = pathinfo($file_name);
				$extend = strtolower($extend["extension"]);
				$file_name_list .= '.' . $extend;    //得到文件后缀
				$upload_file_name = UPLOAD_PATH . '/scores/'.$file_name_list;
				$file_type = move_uploaded_file($_FILES['file']['tmp_name'], $upload_file_name);
				$conn = Yii::app()->db;
				if ($file_type == 1) {
					spl_autoload_unregister(array('YiiBase', 'autoload'));
					include_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/extensions/PHPExcel.php');
					include_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/extensions/PHPExcel/IOFactory.php');
					spl_autoload_register(array('YiiBase', 'autoload'));
					if ($extend == 'xlsx') {
						$type = 'Excel2007';
					}elseif ($extend=='xls') {
						$type = 'Excel5';
					}else {
						$this->redirect('/info/default/index/error/3');exit;
					}
					$xlsReader = PHPExcel_IOFactory::createReader($type);
					$xlsReader->setReadDataOnly(true);
					$xlsReader->setLoadSheetsOnly(true);
					$Sheets = $xlsReader->load($upload_file_name);
					$Sheet = $Sheets->getSheet(0)->toArray();
					$exm_student_score = array();
					$exm_student_score['exam_id'] = $data['exam_id'];
					$exm_student_score['addtime'] = time();
					$importruledetail = Array (
					'学生姓名' => 'student_name',
					'考试号码' => 'exam_code',
					'城市代码' => 'city_code',
					'城市' => 'city_name',
					'学校代码' => 'school_code',
					'学校名称' => 'school_name',
					'班级' => 'class_name',
					'总分' => 'socre',
					'科别代码' => 'disciplin_code',
					'科别' => 'disciplin_name',
					'是否统计' => 'statis',
					'学校性质' => 'nature',
					'星级' => 'interstellar',
					'语文' => 'ywf',
					'数学' => 'sxf',
					'英语' => 'yyf',
					'选修课1' => 'xk1f',
					'选修课2' => 'xk2f',
					'物理' => 'wlf',
					'化学' => 'hxf',
					'生物' => 'swf',
					'政治' => 'zzf',
					'历史' => 'lsf',
					'地理' => 'dlf',
					'语文1' => 'yw1f',
					'语文2' => 'yw2f',
					'语文3' => 'yw3f',
					'语文附加' => 'ywfjf',
					'数学1' => 'sx1f',
					'数学2' => 'sx2f',
					'数学附加' => 'sxfjf',
					'英语1' => 'yy1f',
					'英语2' => 'yy2f',
					'英语3' => 'yy3f',
					'物理1' => 'wl1f',
					'物理2' => 'wl2f',
					'化学1' => 'hx1f',
					'化学2' => 'hx2f',
					'生物1' => 'sw1f',
					'生物2' => 'sw2f',
					'政治1' => 'zz1f',
					'政治2' => 'zz2f',
					'历史1' => 'ls1f',
					'历史2' => 'ls2f',
					'地理1' => 'dl1f',
					'地理2' => 'dl2f'
					);
					//只导入错误行数数据
					if ($_POST['submit']=='只导入错误行数数据'){
						$student_error_sql = 'SELECT "excel_row" FROM "{{import_error}}" WHERE  "type"=4 AND "exam_id"='.$data['exam_id'];
						$student_error_rows = $conn->createCommand($student_error_sql)->queryAll();
						if (empty($student_error_rows)){
							$this->redirect('/scores/out/index/error/2');exit;
						}else {
							$Sheeteroor[0] = $Sheet[0];
							foreach ($student_error_rows as $r){
								$Sheeteroor[$r['excel_row']] = $Sheet[$r['excel_row']];
							}
							$excelary = $Sheeteroor;
						}
					}else {
						$excelary = $Sheet;
					}
					$student_score_sql = array();
					$student_score_error_sql = array();
					$newsqlarray = array();
					foreach ($excelary as $k=>$v){
						if ($k>0) {
							$sheetary = array_combine($excelary[0],$v);
							foreach ($sheetary as $s=>$y){
								if (isset($importruledetail[$s])){
									$exm_student_score[$importruledetail[$s]] = $y;
								}
							}
							if (!empty($exm_student_score['student_name'])){
							$checksql = ' SELECT "student_id" FROM "{{student_out_score}}" WHERE "exam_id" = '.$data['exam_id'].' AND "student_name" like \'%'.$exm_student_score['student_name'].'%\'';
							$pointinfo = $conn->createCommand($checksql)->queryRow();
							if ($pointinfo){
							$errorsql = 'INSERT INTO "{{import_error}}" ("excel_row","info","type","exam_id") VALUES ('.$k.',\'此学生成绩已经存在\',4,'.$data['exam_id'].')';
							$student_score_error_sql[] = $errorsql;
							continue;
							}
							}else {
							$errorsql = 'INSERT INTO "{{import_error}}" ("excel_row","info","type","exam_id") VALUES ('.$k.',\'学生姓名不能为空\',4,'.$data['exam_id'].')';
							$student_score_error_sql[] = $errorsql;
							continue;
							}

								if (isset($exm_student_score['disciplin_name'])){
									$where = ' WHERE "disciplin_nick" like \'%'.$exm_student_score['disciplin_name'].'%\'';
									$disciplininfo = Import::_getdisciplininfo($where);
									if (!empty($disciplininfo)){
										$exm_student_score['disciplin_type'] = $disciplininfo['disciplin_type'];
									}else {
										$errorsql = 'INSERT INTO "{{import_error}}" ("excel_row","info","type","exam_id") VALUES ('.$k.',\'科别'.$exm_student_score['disciplin_name'].'没有科别信息\',4,'.$data['exam_id'].')';
									
							
									$student_score_error_sql[] = $errorsql;
									continue;
								}
							}
							if ($exm_student_score) {
								$sqlkey = array_keys($exm_student_score);
								$sqlkey = '"'.implode('","',$sqlkey).'"';
								$sqlvalue = array_values($exm_student_score);
								$sqlvalue = "'".implode("','",$sqlvalue)."'";
								$sql = 'INSERT INTO "{{student_out_score}}" ('.$sqlkey.') VALUES ('.$sqlvalue.')';
								$student_score_sql[] = $sql;
							}
						}
					}
					
					if ($student_score_error_sql){
						//将本次项目导入错误日志清空
						$error_where = ' WHERE "type"=4 AND "exam_id"='.$data['exam_id'];
						Import::_delimporterror($error_where);
						foreach ($student_score_error_sql as $sql){
							$conn->createCommand($sql)->execute();
						}
						$this->redirect('/scores/out/index/error/4/exam_id/'.$data['exam_id']);exit;
					}else {
						if ($student_score_sql) {
                                foreach ($student_score_sql as $sql){
                                    $conn->createCommand($sql)->execute();
                            }
                        }
                    }
					$this->redirect('/scores/out/index/error/5');exit;
				}
			}
		}
		$this->redirect('/scores/out/index');
	}
    protected function _GetExamList($exam_id = 0,$qwhere, $pageSize = 8) {
        $conn = Yii::app()->db;
        $where = '';
        if ($exam_id > 0) {
            $where = ' WHERE "exam_id" = ' . $exam_id;
            $where .= $qwhere;
        }else{
            $where = !empty($qwhere) ? " WHERE ".$qwhere : '';
        }
        $sql = 'SELECT "student_id","student_name","exam_id","exam_code","school_name","class_name","socre" FROM "{{student_out_score}}" ' . $where;
        $sqlCount = 'SELECT count(*) FROM "{{student_out_score}}" ' . $where;
        $data = ZCommon::getDaoPageList($sql, $sqlCount, $pageSize);
        return $data;
    }
    public function actionUploadexcel(){
        // 请求参数
        $isAjax = isset($_POST['isajax'])?$_POST['isajax']:0;
        $examID = isset($_POST['exam_id'])?$_POST['exam_id']:0;

        // 非法请求 无响应信息
        if($isAjax!=1 || !$this->request->isPostRequest)
            exit;
        if (!$examID || empty($_FILES['file']['name'])) {
            Z::ajaxReturn(201, '考试项目,上传文件为必选项');
        }
        
        // 考试验证
        $examwhere = "SELECT \"exam_status\" FROM \"{{exam}}\" WHERE \"exam_id\"='{$examID}'";
        $exam = Yii::app()->db->createCommand($examwhere)->queryRow();
        if(!$exam){
            Z::ajaxReturn(204, '考试不存在');
        }
        if(!isset($exam['exam_status']) && $exam['exam_status']!=1){
            Z::ajaxReturn(205, '本次考试状态不是上传数据');
        }
        
        // 保存excel
        $file_name_list = ZFileUpload::getUniqueID();  #得到唯一名称
        $file_name = $_FILES['file']['name'];
        $extend = pathinfo($file_name);
        $extend = strtolower($extend["extension"]);
        $file_name_list .= '.' . $extend;              #得到文件后缀
        $upload_file_name = ZPScoreImport::getExcelSavePath(ZPScoreImport::UPLOAD_SCORE).'/'.$file_name_list;
        if(!ZPScoreImport::isSupportExcelVersion($upload_file_name)){
            Z::ajaxReturn(207, '只支持EXCEL(2003)');
        }
        $moveStatus = move_uploaded_file($_FILES['file']['tmp_name'], $upload_file_name);
        if ($moveStatus != 1) {
            Z::ajaxReturn(208, '上传失败');
        }
        
        // 判断excel是否为空
        $excelImport = new ZPScoreImport($upload_file_name, 1);
        $excelInfo = $excelImport->fetchBatchData(1, 0);
        $ExcelRowCount = $excelInfo['rowNum'];
        if( $ExcelRowCount < 2 ){
            $this->ajaxReturn(209,"excel数据为空");
        }
        
        // 判断模板是否正确
        $excelTitle = $excelInfo['title'];
        $excelTitle = ZPScoreImport::deepTrim($excelTitle);
        $excelTitle = $excelTitle?$excelTitle:array();
        $tplExcelTitle = ZPScoreImport::getOutImportRule();
        $diffTh = array();
        foreach ($tplExcelTitle AS $thk => $thv){
            $sindex = array_search($thk, $excelTitle);
            if($sindex === false){
                $diffTh[] = $sindex;
            }else
                unset($excelTitle[$sindex]);
        }
        //var_dump($excelTitle);exit;
        $diffTh = array_merge($diffTh,$excelTitle);
        if($diffTh)
            $this->ajaxReturn(210,"列(".  implode(',', $diffTh).')缺少或与模板中不存在');
        
        
        
        // ajax 返回上传结果
        $salt = ZPScoreImport::salt($file_name_list.$examID."1"."0".$ExcelRowCount);
        $this->ajaxReturn(1,"文件上传成功",array(
            'f'     =>  base64_encode($file_name_list),
            'eid'   =>  $examID,
            'bt'    =>  1,
            'he'    =>  0,
            'salt'  =>  $salt,
            'ct'    =>  $ExcelRowCount
        ));
    }
    public function actionVerifyexcel(){
        // request 参数
        $saveName = urldecode(base64_decode($this->request->getParam('f','')));
        $examID = $this->request->getParam('eid','');
        $batch = intval($this->request->getParam('bt',"0"));
        $hasError = $this->request->getParam('he',"0");
        $reqSalt = $this->request->getParam('salt','');
        $rcount   = $this->request->getParam('ct',0);
        $salt = ZPScoreImport::salt($saveName.$examID.$batch.$hasError.$rcount);
        $saveNamePathinfo = explode('.', $saveName);
        $uniqueFileName = $saveNamePathinfo[0];
        
        // 非正常请求
        if(empty($saveName) || empty($examID) || empty($reqSalt) || $batch<1)
            $this->ajaxReturn(201,'校验失败');
        if($reqSalt !== $salt)
            $this->ajaxReturn(202,'校验失败');
        $excelFilePath = trim(ZPScoreImport::getExcelSavePath(ZPScoreImport::UPLOAD_SCORE),"\\/").DIRECTORY_SEPARATOR.$saveName;
        if(!file_exists($excelFilePath)){
            $this->ajaxReturn(203,'校验失败');
        }
        		
        
        $importruledetail = ZPScoreImport::getOutImportRule();

            // 读取excel数据
        $excelImport = new ZPScoreImport($excelFilePath, 1);
        $pdata = $excelImport->fetchBatchData($batch, ZPScoreImport::BATCHNUM);
        $excelary = $pdata['data'];
        $rowCount = count($excelary);
        $sheetTitle = $pdata['title'];
        $sheetTitle = ZPScoreImport::deepTrim($sheetTitle);
        $sheetTitle = $sheetTitle?$sheetTitle:array();;

        // 数据库中可用可用科别
        $dpSql = 'SELECT "disciplin_nick","disciplin_code","disciplin_type"  FROM "{{disciplin}}" WHERE "is_del"=0';
        $dbDp = array();
        $dbDpRow = Yii::app()->db->createCommand($dpSql)->queryAll();
        if($dbDpRow){
            foreach($dbDpRow AS $dpRv){
                $dbDp[$dpRv['disciplin_nick']] = $dpRv;
            }
        }

        // 数据库和缓存中考生号
        $dbExamCodes = array();     # 判断数据库中是否存在考生号码
        $batchExamCodes = array();  # 批数据中所有的考生号
        $cacheExamCodes = ZPScoreImport::fetchUniqueCache($uniqueFileName);
        $cacheExamCodes = $cacheExamCodes?$cacheExamCodes:array();
        $examCodeIndex = array_search('考试号码', $sheetTitle);   #考号对应的excel列下标
        if($examCodeIndex !== false){
            foreach($excelary AS $v){
                $sheetExamCode = isset($v[$examCodeIndex])?trim($v[$examCodeIndex]):null;
                if($sheetExamCode){
                    $batchExamCodes[$sheetExamCode] = $sheetExamCode;
                }
            }
        }
        if($batchExamCodes){
            $batchExamCodes = implode("','", $batchExamCodes);
            $dbCodeSql = "SELECT \"exam_code\" FROM  \"{{student_out_score}}\" WHERE \"exam_code\" IN ('{$batchExamCodes}')";
            $studentRow = Yii::app()->db->createCommand($dbCodeSql)->queryAll();
            if($studentRow)
                foreach($studentRow AS $studentRv){
                    $dbExamCodes[$studentRv['exam_code']] = 1;
                }
            unset($studentRow,$dbCodeSql,$batchExamCodes);
        }



        $batch_sql = "";
        $batch_error_sql = "";
        foreach ($excelary as $k=>$v){
            $exm_student_score = array();
            $exm_student_score['exam_id'] = $examID;
            $exm_student_score['addtime'] = time();
            $errorRow = ZPScoreImport::BATCHNUM * ($batch -1) + 2;
            $sheetary = array_combine($sheetTitle,$v);
            foreach ($sheetary as $s=>$y){
                if (isset($importruledetail[$s])){
                    $exm_student_score[$importruledetail[$s]] = $y;
                }
            }
             
            // 学生姓名不能为空
            if (!isset($exm_student_score['student_name'])){
                $batch_error_sql .= 'INSERT INTO "{{import_error}}" ("excel_row","info","type","exam_id") VALUES (' . $errorRow . ',\'姓名不能为空\',4,' . $examID . ');
                    ';
                continue;
            }
            $exm_student_score['student_name'] = preg_replace('/[\s| ]+/', '', $exm_student_score['student_name']);

                // 考生号重复判断
            $exm_student_score['exam_code'] = isset($exm_student_score['exam_code'])?$exm_student_score['exam_code']:'';
            if(isset($dbExamCodes[$exm_student_score['exam_code']]) || isset($cacheExamCodes[$exm_student_score['exam_code']])){
                $batch_error_sql .= ' INSERT INTO "{{import_error}}" ("excel_row","info","type","exam_id") VALUES (' . $k . ',\'此' . $exm_student_score['exam_code'] . '考号已经存在\',4,' . $examID . '); 
                                    ';
                continue;
            }
            if($exm_student_score['exam_code']){
                $cacheExamCodes[$exm_student_score['exam_code']] = 1;
            }

            // 科别判断
            $exm_student_score['disciplin_name'] = isset($exm_student_score['disciplin_name'])?$exm_student_score['disciplin_name']:"";
            if ($exm_student_score['disciplin_name']){
                if(isset($dbDp[$exm_student_score['disciplin_name']])) {
                    $exm_student_score['disciplin_code'] = $dbDp[$exm_student_score['disciplin_name']]['disciplin_code'];
                    $exm_student_score['disciplin_type'] = $dbDp[$exm_student_score['disciplin_name']]['disciplin_type'];
                }else{
                    $batch_error_sql .= 'INSERT INTO "{{import_error}}" ("excel_row","info","type","exam_id") VALUES (' . $errorRow . ',\'此科别'.$exm_student_score['disciplin_name'].'没有科别信息\',4,' . $examID . ')
                        ';
                    continue;
                }
            }

            if ($exm_student_score) {
                $sqlkey = array_keys($exm_student_score);
                $sqlkey = '"'.implode('","', $sqlkey).'"';
                $sqlvalue = array_values($exm_student_score);
                $sqlvalue = "'" . implode("','", $sqlvalue) . "'";
                $sql = 'INSERT INTO "{{student_out_score}}" (' . $sqlkey . ') VALUES (' . $sqlvalue . ');
                        ';
                $batch_sql .= $sql;
            }
        }
		ZPScoreImport::saveUniqueCache($cacheExamCodes, $uniqueFileName);			
		if ($batch_error_sql) {
            //将本次项目导入之前错误日志清空
            if($batch == 1){
                $batch_error_sql = "DELETE FROM \"{{import_error}}\"  WHERE \"type\"=1 AND \"exam_id\"= '{$examID}';
                                    {$batch_error_sql}";
            }
            //echo $batch_error_sql;exit;
            $hasError = 1;
            ZPScoreImport::clearBatchSqlAll($uniqueFileName);
            $batch_error_sql = "DECLARE
                               BEGIN
                               {$batch_error_sql}
                               END;"; 
            Yii::app()->db->createCommand($batch_error_sql)->execute();
        } else {
            if ($batch_sql) {
                $batch_sql = " --<$rowCount>
                               DECLARE
                               BEGIN
                               {$batch_sql}
                               END;";
                ZPScoreImport::saveBatchSql($batch, $uniqueFileName, $batch_sql);
            }
        }
        $readStatus = $pdata['readEnd'];
        // ajax 返回验证结果
        if($readStatus == 1){
            $batch = 1;
        }else{
            $batch ++;
        }
        $salt = ZPScoreImport::salt($saveName.$examID.$batch.$hasError.$rowCount);
        $this->ajaxReturn($readStatus,"文件上传成功",array(
            'f'     =>  base64_encode($saveName),
            'eid'   =>  $examID,
            'bt'    =>  $batch,
            'he'    =>  $hasError,
            'salt'  =>  $salt,
            'ct'    =>  $rowCount
        ));
    }
    public function actionSaveexcel(){
        // request 参数
        $saveName = urldecode(base64_decode($this->request->getParam('f','')));
        $examID = $this->request->getParam('eid','');
        $batch = $this->request->getParam('bt',0);
        $hasError = $this->request->getParam('he',0);
        $reqSalt = $this->request->getParam('salt','');
        $rcount   = $this->request->getParam('ct',0);
        $salt = ZPScoreImport::salt($saveName.$examID.$batch.$hasError.$rcount);
        $saveNamePathinfo = explode('.', $saveName);
        $uniqueFileName = $saveNamePathinfo[0];
        if(empty($uniqueFileName) || empty($saveName) || empty($examID)  || empty($reqSalt) || $batch<1)
            $this->ajaxReturn(201,'校验失败');
        if($reqSalt !== $salt)
            $this->ajaxReturn(202,'校验失败');
        
        
        $count = 0;
        $content = ZPScoreImport::fetchBatchSql($batch, $uniqueFileName);
        if($content){
            $begin  = strpos($content,'<')+1;
            $end  = strpos($content,'>');
            $count = substr($content, $begin, $end-$begin);
            Yii::app()->db->createCommand($content)->query();
            //@unlink($sqlFile);
            // ajax 返回验证结果
            $batch ++;
            $salt = ZPScoreImport::salt($saveName.$examID.$batch.$hasError.$count);
            $this->ajaxReturn(2,"文件上传成功",array(
                'f'     =>  base64_encode($saveName),
                'eid'   =>  $examID,
                'bt'    =>  $batch,
                'he'    =>  $hasError,
                'salt'  =>  $salt,
                'ct'    =>  $count,
            ));
        }
        $this->ajaxReturn(1);
    }
     //更新功能
    public function actionUpdate(){
        $this->title = '学生信息设置';
        $this->layout = "//layouts/main_window";
        $data = array();
        $sid = $this->request->getParam('sid');
        $eid = $this->request->getParam('eid');
        $zedu = new ZEdu();
        if($sid>0 && $eid>0){
            $data = $zedu->_getOutExamInfo($sid,$eid);
        }
        //保存更新信息
        if (isset($_POST['submit']) && !empty($_POST['submit'])) {
            $status = $zedu->_updOutExamScore($_POST['student_id'],$_POST['exam_id'],$_POST);
            if ($status) {
                $this->frameAjaxMessage('/scores/out/index');
                exit;
            } else {
                $this->frameAjaxMessage(null, '更新失败');
                exit;
            }
        }
        $this->render('update',array(
            'data'  => $data
        ));
    }
    //删除功能
    public function actionDelete(){
        $status = 0;
        $sid = $this->request->getParam('sid');
        $eid = $this->request->getParam('eid');
        if($sid>0 && $eid>0){
            $zedu = new ZEdu();
            $status = $zedu->_delOutScore($sid,$eid);
        }
        echo $status;
    }
    private function ajaxReturn($code,$msg='',$ext=''){
        $res = array('code'=>$code,'msg'=>$msg, 'ext'=>$ext);
        echo  json_encode($res);exit;
    }
}
